package com.lazyfish.superdir.controller;


import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.lazyfish.superdir.entity.WordInfo;
import com.lazyfish.superdir.service.WordInfoService;
import com.lazyfish.util.ResultBuild;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
@CrossOrigin
@Controller
public class WordInfoController {
    @Autowired
    private WordInfoService wordInfoService;
    @RequestMapping("/getTotal")
    @ResponseBody
    public int getTotal(HttpServletRequest request, HttpServletResponse response) {
        int num = wordInfoService.getTotal();
        return num;
    }
    @RequestMapping("/getWordInfo")
    @ResponseBody
    public WordInfo getWordInfo(HttpServletRequest request, HttpServletResponse response) {
        int id = Integer.parseInt(request.getParameter("id"));
        WordInfo wordInfo = wordInfoService.getWordInfo(id);
        return wordInfo;
    }
    @RequestMapping("/getWordInfo2")
    @ResponseBody
    public WordInfo getWordInfo2(HttpServletRequest request, HttpServletResponse response) {
        int id = Integer.parseInt(request.getParameter("id"));
        WordInfo wordInfo = wordInfoService.getWordInfo2(id);
        return wordInfo;
    }
    @RequestMapping("/getWordInfoByName")
    @ResponseBody
    public List<WordInfo> getWordInfoByName(HttpServletRequest request, HttpServletResponse response) {
        String name = request.getParameter("name");
        List<WordInfo> list = wordInfoService.getWordInfoByName(name);
        return list;
    }
    @RequestMapping("/addWordInfo")
    @ResponseBody
    public ResultBuild addWordInfo(WordInfo wordInfo) {
        return new ResultBuild(200,wordInfo);

    }
}
